<template>
  <div class="layout-container test-sample-selected" v-loading="stepLoading">
    <!-- <div class="search">
      <el-input
        v-model="keyword"
        style="width: 320px"
        placeholder="请搜索"
        clearable
      ></el-input>
      <el-button type="primary" :icon="Search" @click="onQuery({ pageNo: 1 })"
        >查找</el-button
      >
    </div> -->
    <TagIcon title="选取处理方式" :style="tagIconStyle" />
    <div class="selected-deal-way">
      <div class="static-evaluate">
        <span>静态评估选取相似度前</span>
        <el-input-number v-model="numbers" :min="0" :max="10000" />
        <span>项</span>
      </div>
      <div class="dynmic-caluate-way">
        <p>动态评估选取计算方式:</p>
        <el-checkbox-group
          v-model="checkedCities"
          @change="handleCheckedCitiesChange"
        >
          <el-checkbox
            v-for="city in cities"
            :key="city.id"
            :label="city.id"
            :value="city.id"
          >
            {{ city.name }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </div>

    <div class="layout-container-table">
      <CommonTable
        :data="state.tableData"
        v-model:page="page"
        :total="total"
        v-loading="loading"
        highlight-current-row
        @onQuery="onQuery"
        @selection-change="onSelectChange"
      >
        <el-table-column prop="sampleName" label="试验样本名称" />
        <el-table-column prop="dytStyle" label="导引头体制" />
        <el-table-column prop="interType" label="干扰类型" />
        <el-table-column prop="interScenType" label="干扰场景类型" />
        <el-table-column
          prop="foreignElectEquip"
          label="外军电子战装备类型"
          width="150"
        />

        <el-table-column prop="updateTime" label="更新时间" width="150" />
        <el-table-column prop="studen" label="评估状态" width="160">
          <!--   0-原始样本
                  1-完成数据处理
                  2-完成静态相似性评估
                  3-完成动态相似性评估
                  4-完成性能推算
                  5-完成边界推算 -->
          <template #default="scope">
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '1'"
            >
              <div class="round" style="background: rgba(22, 168, 49, 1)"></div>
              <span style="color: rgba(22, 168, 49, 1)">未评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '2'"
            >
              <div class="round" style="background: #ff69ab"></div>
              <span style="color: #ff69ab">完成静态相似性评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '3'"
            >
              <div class="round" style="background: #fe8b42"></div>
              <span style="color: #fe8b42">完成动态相似性评估</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '4'"
            >
              <div class="round" style="background: #ff00ff"></div>
              <span style="color: #ff00ff">完成性能推算</span>
            </div>
            <div
              class="evaluation-process"
              v-if="scope.row.evaluationStage === '5'"
            >
              <div class="round" style="background: #8000ff"></div>
              <span style="color: #8000ff">完成边界推算</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="60">
          <template #default="scope">
            <el-button
              link
              type="primary"
              size="small"
              :disabled="!(scope.row.evaluationStage === '3')"
              @click="onLook(scope.$index, scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </CommonTable>
    </div>

    <div class="step-buttons common-buttons">
      <el-button type="primary" @click="onStep">开始快速处理</el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ElMessage, FormInstance, ElMessageBox, ElTable } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import CommonTable from "@/components/common-table/index.vue";
import { Page } from "@/components/common-table/type";
import TagIcon from "@/components/tag-icon/index.vue";
import {
  httpPatchEvaluateList,
  httpBatchEvaluation,
} from "@/api/similarityEvaluationSystem";
import { joinStr } from "@/utils/tools";

let $router = useRouter();
const tagIconStyle = reactive({ paddingLeft: "16px", paddingTop: "16px" });
const numbers = ref<number>(0);
// 多选组
const checkedCities = ref([]);
const cities = [
  { id: "DTW", name: "基于动态时间弯曲的序列距离" },
  { id: "shape", name: "基于灰色关联度的形状相似性" },
  { id: "cosine", name: "融合注意力机制的动态特征向量相似度" },
];
// 模糊搜索
const keyword = ref<string>("");
const state = reactive<any>({
  tableData: [],
});
const loading = ref<boolean>(false);
const stepLoading = ref<boolean>(false);
const page = reactive<Page>({
  current: 1,
  pageSize: 20,
});
const total = ref<number>(0);
const rowsList = ref([]);
const selectKeys = ref<string[]>([]);

onMounted(() => {
  onQuery({ pageNo: 1 });
});

// 多选框勾选
const handleCheckedCitiesChange = (value: string[]) => {};

// 查询数据
const onQuery = (val: any) => {
  const params = {
    sampleType: "1",
    sampleId: "",
    sampleName: keyword.value,
    evaluationStage: "1",
    pageSize: page.pageSize,
    pageNo: page.current,
    ...val,
  };
  loading.value = true;
  httpPatchEvaluateList(params).then((res) => {
    const result = res.data;
    loading.value = false;
    const { rows, totalRows } = result;
    total.value = totalRows;
    state.tableData = rows;
    selectKeys.value = [];
    rowsList.value = [];
  });
};

// 过滤出keys
const filterKeys = (arr: any) => {
  let keys: string[] = [];
  for (let item of arr) {
    keys.push(item.id);
  }
  return keys;
};

// 查看结果
const onLook = (index: number, row: any) => {
  $router.push({
    path: "/similarityEvaluateSystem/resultVisualDisplay",
    query: {
      layerType: "look",
      dealSampleId: row.id,
      sampleName: row.sampleName,
    },
  });
};

// 下一步
const onStep = () => {
  if (!(selectKeys.value.length)) {
    ElMessage({
      message: "请选择要处理的数据!",
      type: "warning",
    });
    return;
  }

  if(!(checkedCities.value.length)) {
    ElMessage({
      message: "请选择动态评估选取计算方式!",
      type: "warning",
    });
    return;
  }

    if(numbers.value === 0) {
    ElMessage({
      message: "请选择静态评估选取相似度!",
      type: "warning",
    });
    return;
  }
  const params = {
    items: numbers.value,
    method: joinStr(checkedCities.value),
    sampleIds: joinStr(selectKeys.value),
  };
  stepLoading.value = true;
  httpBatchEvaluation(params).then((res: any) => {
    const { code } = res;
    stepLoading.value = false;
    if (code === 200) {
      localStorage.setItem("patchEvaluates", JSON.stringify(rowsList.value));
      selectKeys.value = [];
      checkedCities.value = [];
      numbers.value = 0;
      rowsList.value = [];
      $router.push({
        path: "/similarityEvaluateSystem/resultList",
        query: {},
      });
    }
  });
};

// 选择监听器
const onSelectChange = (val: []) => {
  rowsList.value = val;
  selectKeys.value = filterKeys(val);
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/buttons";
.test-sample-selected {
  .search {
    display: flex;
    padding: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    :deep() {
      .el-input--small .el-input__wrapper {
        margin-right: 10px;
      }
    }
  }

  .selected-deal-way {
    display: flex;
    justify-content: space-between;
    padding-left: 26px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding-bottom: 10px;
    .static-evaluate span {
      font-size: 14px;
      padding: 0 5px;
    }
    .dynmic-caluate-way {
      display: flex;
      margin-right: 30px;

      p {
        position: relative;
        top: 4px;
        margin: 0;
        right: 10px;
        font-size: 14px;
      }
    }
  }
  :deep(.el-checkbox__input.is-checked .el-checkbox__inne) {
    background: rgb(1, 18, 90);
    border-color: rgb(1, 18, 90);
  }

  :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: rgb(1, 18, 90);
  }

  :deep(.el-checkbox.el-checkbox--small .el-checkbox__label) {
    font-size: 13px;
  }

  .layout-container-table {
    padding: 5px 15px;
    .el-button--small {
      background: transparent;
      // color: rgba(24, 81, 237, 1);
      font-size: 13px;
    }
  }

  .evaluation-process {
    display: flex;
    cursor: pointer;
    // color: rgb(24, 81, 237);
    .round {
      display: inline-block;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      position: relative;
      top: 7px;
      right: 4px;
    }
  }

  .step-buttons {
    display: flex;
    justify-content: center;
    box-shadow: 0px 0px 10px rgba(218, 222, 224, 1);
    padding: 10px 0;
  }
}
</style>
